
*** Set up directories

global data ** folder with data **
global tables ** folder for tables **
global figures ** folder for figures **


clear all
cap log close
log using 3reg_familyoutcomes.log , replace

set matsize 10000
set maxvar 10000

set more off

cd $data

use familyoutcomes.dta, replace
	
/******************************************
	PREPARATION FOR REGRESSIONS
******************************************/	
	
** Make globals with 3-way interaction between education, race, and state and race-state trends for inclusion in regressions
**Notes: 
	*** Variables e1-e* are dummies for education, r1-r* are dummies for race, s1-s51 are dummies for state, ///
	*** Variables  e`e's`s'r`r' are interactions between all combinations of e, s, and r dummies
	*** Variables
			
	tab educ
		local maxed =r(r)
	tab race
		local maxrace =r(r)
	tab fipstate
		local maxstate= r(r)
	
	global threeway ""

	forvalues e = 1/`maxed' {
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global threeway $threeway e`e's`s'r`r'
		
	}
	}
	}

	global racestatetrend ""
	
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global racestatetrend $racestatetrend s`s'r`r'year
		
	}
	}
	
/*********************************************************************
	REGRESSIONS WITH BASELINE SPECIFICATION (RELATIVE WAGE + AVERAGE WAGE)
	AND BASELINE CONTROLS 
********************************************************************/
	
	** Tables 2-5: Marriage (2), Cohabitation (3), Spousal Education (4), and Labor Market Outcomes (5)
	** Table A6: Impacts on Spousal Age
	** Table A7: Impacts on HH Income
	** Table A17: Marriage Impacts by Whether Have Children in HH
	
	eststo clear
	
	foreach outcome in ///
	 share_married_10fem share_nevmar_10fem share_div_10fem /// Table 2
	 cohab_offic_10fem  hhf1m1_mar_10fem hhf1m1_sing_10fem  adulthhfem2only_10fem  adulthh1_10fem  adulthh3up_10fem  /// Table 3
	 ed_gr_sp_10fem ed_same_sp_10fem ed_lt_sp_10fem diff_sp_ed_10fem /// Table 4
	 ave_wkhrs_10fem  ave_lnwkinc_10fem ave_lninc_10fem posinc_10fem wkswork_10fem share_emp_10fem share_inlf_10fem  /// Table 5
	 age_gr_sp_10fem age_same_sp_10fem age_lt_sp_10fem  sp_13_older_10fem sp_4pl_older_10fem  sp_13_ynger_10fem sp_4pl_ynger_10fem  abs_dage_sp_10fem /// Table A6
	 earn_shhh_10fem sngfern_10fem sngmern_10fem multern_10fem /// Table A7
	 anykids_10fem marrmom3_10fem marrnomom2_10fem nevmarrmom3_10fem nevmarrnomom2_10fem  divmom3_10fem  divnomom2_10fem       /// Table A17
	{	
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 			
		local controls yrsedfem yrsedmale  sexratio 

		eststo ra_`outcome': xi: reg `outcome' lncpsshiftrelwage lncpsaveshiftwage i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
				 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
				`fe'  /// 		
				`controls' ///				
				[aweight=popfem], cluster(fipstate) 	
			estadd local Ave_wage = "Yes"				
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10
					
	}
	
	** Insensitivity to effects when average wage not controlled for (Table 2 Panel A)
	
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem {
	
		eststo r_`outcome': xi: reg `outcome' lncpsshiftrelwage i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
					 `educyear'  `raceyear' `stateyear' $racestatetrend 	/// 
					`fe'  /// 		
					`controls'  ///				
					[aweight=popfem], cluster(fipstate) 				
			estadd ysumm
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10	
	
	}
	
/*****************************************************
	OUTPUT BASELINE TABLES
******************************************************/
	
	*** Table 2: Stack results with and without control for average wage

	**Table 2, Panel A: Marriage results without control for average wage
	
	esttab r_share_married_10fem  r_share_div_10fem  r_share_nevmar_10fem  /// 
		using "${tables}/table2.tex", replace /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		`mgroup' ///
		stat(N , /// 
		labels("Obs" ) /// 
		fmt( 0 0 0 0 0 )) ///
		label mtitle( "Married" "Divorced" "Never Married" ) postfoot("")	/// 
		varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{A: Relative only}} \\ "))	

	**Table 2, Panel B: Marriage results controlling for average wage
	
	esttab ra_share_married_10fem  ra_share_div_10fem  ra_share_nevmar_10fem  /// 
		using "${tables}/table2.tex", append /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
		stat(mean10  N , labels("Mean Y" "Obs" ) fmt(3 0  )) ///
		label nomtitle prehead("") posthead("") ///
		varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" lncpsaveshiftwage "Effect of 10\% Increase in Avg. Wage" ///
		, blist(lncpsshiftrelwage "\midrule \it{\underline{B: Relative controlling for Average}} \\ "))		

	*** Tables 3-5, A6, A7, and A17:
	
	foreach table in table3 table4 table5 tablea6 tablea7 tablea17	{

		if "`table'" == "table3" {
			local mgroup mgroups("Cohab. " "Only Other Adult in HH is:" "Live Alone" "2+ Other Adults", pattern(1 1 0 0 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle  "Official Rept." "Husband" "Single Male"  "Female" "" ""
			local outspec ra_cohab_offic_10fem ra_hhf1m1_mar_10fem ra_hhf1m1_sing_10fem  ra_adulthhfem2only_10fem  ra_adulthh1_10fem  ra_adulthh3up_10fem
		}			
		
		if "`table'" == "table4" {
			local mgroup mgroups("Spouse Ed., Relative to Own" "Spouse Minus Own Ed.", pattern(1 0 0 1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle "Less" "Same" "More" " " 
			local outspec ra_ed_gr_sp_10fem ra_ed_same_sp_10fem ra_ed_lt_sp_10fem ra_diff_sp_ed_10fem 
		}			
		
		if "`table'" == "table5" {
			local mgroup mgroups("Conditional On Working" "Unconditional", pattern(1 0 0 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle "Wkly Hrs"  "Weeks Worked"  "ln(Wkly Inc)" "ln(Inc)" "Any Earnings" "In Labor Force"
			local outspec ra_ave_wkhrs_10fem ra_wkswork_10fem  ra_ave_lnwkinc_10fem ra_ave_lninc_10fem   ra_posinc_10fem ra_share_inlf_10fem 
		}		
			
		if "`table'" == "tablea6" {
			local mgroup mgroups("Spouse Age, Relative to Own" "Spouse Older by" "Spouse Younger by" "Age Gap", pattern(1 0 0 1 0 1 0 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle  "Younger" "Same" "Older" "Up to 3 Yrs" "4+ Yrs"  "Up to 3 Yrs" "4+ Yrs"  "Absolute" 
			local outspec  ra_age_gr_sp_10fem ra_age_same_sp_10fem ra_age_lt_sp_10fem  ra_sp_13_older_10fem ra_sp_4pl_older_10fem  ra_sp_13_ynger_10fem ra_sp_4pl_ynger_10fem ra_abs_dage_sp_10fem 
		}	
				
		if "`table'" == "tablea7" {
			local mgroup mgroups("Own Share of Earnings in" "Income Contributor(s) in Household:", pattern(1 1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle   "Household" "Fem. Breadwinner" "Male Breadwinner"  "Multiple"  
			local outspec  ra_earn_shhh_10fem ra_sngfern_10fem ra_sngmern_10fem ra_multern_10fem
		}		
		
		if "`table'" == "tablea17" {
			local mgroup  mgroups("Any Kids" "Married w/" "Nev. Married w/" "Divorced w/", pattern(1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
			local mtitle " " "Kids" "No Kids" "Kids" "No Kids" "Kids" "No Kids"
			local outspec  ra_anykids_10fem ra_marrmom3_10fem ra_marrnomom2_10fem  ra_nevmarrmom3_10fem ra_nevmarrnomom2_10fem ra_divmom3_10fem  ra_divnomom2_10fem 
	
		}	

		
		esttab `outspec'  /// 
				using "${tables}/`table'.tex", replace /// 
				keep(*lncps*rel*  ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
				`mgroup' ///
				stat(mean10 N Ave_wage, /// 
				labels("Mean Y"  "Obs"  "Average Wage") /// 
				fmt(3 0 0 )) varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage") ///
				label mtitle( "`mtitle'" ) 

	}
	

	
/****************************************************
	ALTERNATIVE SPECIFICATIONS AND ROBUSTNESS TABLES
****************************************************/

	
/************************************************
	Table 6 - Effects by Age and Education
***********************************************/
	
	eststo clear
	
	gen a2230 = (year-birthyr)<=30 & (year-birthyr)>=22
	gen a3144 = (year-birthyr)<=44 & (year-birthyr)>=31

	foreach outcome in  share_nevmar_10fem share_div_10fem { 
	foreach age in a2230 a3144 {
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 
		local controls yrsedfem yrsedmale  sexratio
		
		eststo `age'`outcome': xi: reg `outcome' lncpsshiftrelwage_loed lncpsshiftrelwage_hied lncpsaveshiftwage_loed lncpsaveshiftwage_hied ///
				i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
				 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
				`fe'  /// 		
				`controls' ///				
				[aweight=popfem] if `age'==1, cluster(fipstate) 
			summ `outcome' if  loed ==1 & `age'==1 [aweight=popfem]
			if  strpos("`outcome'", "_10")>0 estadd scalar mean_lths = r(mean)*10
			summ `outcome' if  hied==1 & `age'==1 [aweight=popfem]
			if  strpos("`outcome'", "_10")>0 estadd scalar mean_scol = r(mean)*10
				
			
	}
	}

		esttab  *2230*nevmar_* *3144*nevmar_*  using ///
		"${tables}/table6.tex", replace /// 
		keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonum nonotes noconstant noobs ///
		stat( N mean_lths mean_scol, labels("Obs" "Mean Y - Low-Skill" "Mean Y - High-Skill") fmt(0 3 3)) ///
		label	mtitle( "22-30" "31-44" )	 ///
		varlabels(lncpsshiftrelwage_loed  "Effect of 10\% Increase in Rel. Wage x Low Skill" lncpsshiftrelwage_hied "Effect of 10\% Increase in Rel. Wage x High Skill", /// 
		blist(lncpsshiftrelwage_loed "\midrule \it{\underline{A: Never Married}} \\ "))	postfoot("")

		esttab  *2230*div_* *3144*div_*   using ///
		"${tables}/table6.tex", append /// 
		keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonum nonotes noconstant noobs ///
		stat(N mean_lths mean_scol, labels( "Obs" "Mean Y - Low-Skill" "Mean Y - High-Skill") fmt(0 3 3 ))  ///
		label	nomtitle	 ///
		varlabels(lncpsshiftrelwage_loed "Effect of 10\% Increase in Rel. Wage x Low Skill" lncpsshiftrelwage_hied "Effect of 10\% Increase in Rel. Wage x High Skill", /// 
		blist(lncpsshiftrelwage_loed "\midrule \it{\underline{B: Divorce}} \\ "))	prehead("") posthead("")
				

/******************************************************
	Table 7 - Regression of Future Wages on Past Outcomes
*********************************************************/

	use $data/table7.dta, clear
	
	gen rel = .
	gen ave = .

	local i = 1 //counter
	eststo clear
	foreach x in changemar6070_10  changenevmar6070_10 changediv6070_10 changeed_gr_sp_10 changeed_lt_sp_10 changesinglemomfem6070_10 changehrsworkfem6070_10 changepovertyfem6070_10  {
	foreach yr in 8090 9000 0010 {
		
		replace rel = changeshiftrel`yr' 
		replace ave = changeshiftave`yr'
		
	
		eststo r`i': xi: reg  `x' rel ave changeyrsedfem changeyrsedmale changesexratio  i.race_num*i.fipstate i.educ_num i.fipstate  [aweight=cps_pop], cluster(fipstate)  
	
	local i = `i'+1 //counter
					
	}
	}			

			 esttab r1 r4 r7 r10 r13 r16 r19 r22 using "${tables}/table7.tex", /// 
			replace keep(rel ) ///
			se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
			stat(N, labels("Obs") fmt(0 )) mtitle("Marr." "Nev. Marr" "Divorced" "Sp. Less Ed" "Sp. More Ed" "Single Mom"  "Hours Work" "Poverty"  ) label /// 
			varlabels(rel "Effect of 10\% Increase in Rel. Wage" , blist(rel "\midrule \it{\underline{A: 1980-1990 Relative Wage}} \\ "))		  ///	
			mgroups("Dep. Var: 60-70 Change in:", pattern(1 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
			suffix(}) span erepeat(\cmidrule(lr){@span})) 	///
			postfoot("")
			
			 esttab r2 r5 r8 r11 r14 r17 r20 r23 using "${tables}/table7.tex", /// 
			append keep(rel ) ///
			se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
			stat(N, labels("Obs")	fmt(0)) label varlabels(rel "Effect of 10\% Increase in Rel. Wage" , blist(rel "\midrule \it{\underline{B: 1990-2000 Relative Wage}} \\ "))		  ///	
			postfoot("") prehead("") posthead("") nomtitle

			 esttab r3 r6 r9 r12 r15 r18 r21 r24 using "${tables}/table7.tex", /// 
			append keep(rel ) ///
			se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
			stat(N , labels( "Obs" ) fmt(0))  label varlabels(rel "Effect of 10\% Increase in Rel. Wage" , blist(rel "\midrule \it{\underline{C: 2000-2010 Relative Wage}} \\ "))		  ///	
			prehead("")	posthead("")	nomtitle
		


/******************************************************
	Table A5 - Effects on Education Composition of Market
*******************************************************/
		
eststo clear
	
	foreach outcome in  rel_yrsed diff_yrsed {
	
	gen `outcome'_10 = `outcome'/10
	
	local controls sexratio  // do not control for yrs ed since that is the outcome

			eststo: xi: reg `outcome'_10  lncpsshiftrelwage lncpsaveshiftwage i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
						`educyear'  `raceyear' `stateyear' 	/// 
						`fe'  /// 		
						`controls' ///				
						[aweight=popfem], cluster(fipstate) 	
				estadd local Ave_wage = "Yes"
				sum `outcome' [aw = popfem]
				estadd scalar mean10 = r(mean)

							
	}
	
		
				esttab   using "${tables}/tablea5.tex", replace /// 
				keep(lncps*rel* ) se se(3) b(3)  star (* .10 ** .05 *** .01)  num nonotes noconstant noobs ///
				label	mtitle( "Male/Fem Ed" "Male-Fem Ed") ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" ) ///
				stat(mean10 N , labels("Mean Y" "Obs" ) fmt(3 0))			


/**************************************************
	Table A8 - Effects by Education and Race
***************************************************/
		
	** Table A8, Panel A: Interaction with Education

	eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 	
	
		qui eststo ed_`outcome': xi: reg `outcome' lncpsshiftrelwage_loed lncpsshiftrelwage_hied lncpsaveshiftwage_loed lncpsaveshiftwage_hied ///
				i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
				`educyear'  `raceyear' `stateyear' $racestatetrend	/// 
				`fe'  /// 		
				`controls' ///				
				[aweight=popfem], cluster(fipstate) 
			test _b[lncpsshiftrelwage_loed] = _b[lncpsshiftrelwage_hied]
			estadd local test_diff = round(`r(p)',.001)

	}
	
	esttab using "${tables}/tablea8.tex", replace /// 
		keep(*lncps*rel* ) se se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat(test_diff , labels("Equality P-value") fmt(3)) noobs /// 
		label mtitle( "Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work" ) postfoot("")	/// 
		varlabels(lncpsshiftrelwage_loed  "Effect of 10\% Increase in Rel. Wage x Low Skill" /// 
		lncpsshiftrelwage_hied "Effect of 10\% Increase in Rel. Wage x High Skill", blist(lncpsshiftrelwage_loed  "\midrule \it{\underline{A: Interaction with Education}} \\ "))		

	
	** Table A8, Panel B: Interaction with Race

	eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {

		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 
		
		eststo race_`outcome': xi: reg `outcome' lncpsshiftrelwage_blk lncpsshiftrelwage_hisp lncpsshiftrelwage_wht lncpsaveshiftwage_blk lncpsaveshiftwage_hisp lncpsaveshiftwage_wht ///
					i.race_num i.educ_num i.year i.fipstate i.birthyr i.birthyr*i.year /// 
					`educyear'  `raceyear' `stateyear' $racestatetrend	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 
			test _b[lncpsshiftrelwage_blk] = _b[lncpsshiftrelwage_hisp] = _b[lncpsshiftrelwage_wht]
			scalar test_diff = r(p)
			estadd scalar test_diff

	}
		
	esttab using "${tables}/tablea8.tex", append /// 
		keep(*lncps*rel* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
		stat(N test_diff , labels("Obs" "Equality P-value" ) fmt(0 3)) ///
		label nomtitle prehead("") posthead("") ///
		varlabels( lncpsshiftrelwage_blk  "Effect of 10\% Increase in Rel. Wage x Black" lncpsshiftrelwage_wht "Effect of 10\% Increase in Rel. Wage x White" lncpsshiftrelwage_hisp "Effect of 10\% Increase in Rel. Wage x Hispanic", ///
		blist(lncpsshiftrelwage_blk "\midrule \it{\underline{B: Interaction with Race}} \\ "))	


/**************************************************
	Table A9 - Effects by Decade
***************************************************/

	eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem  {
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 

		eststo: xi: reg `outcome' lncpsshiftrelwage_y* lncpsaveshiftwage i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
					 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 		
		
	}

	esttab using "${tables}/tablea9.tex", replace /// 
		keep(*lncps*rel* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat( N,  labels("Obs"  ) fmt(0 )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced"  ) 
	
	
/**************************************************
	Table A10 - Insensitivity to including lagged wages
***************************************************/

	eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 


		eststo : xi: reg `outcome' lncpsshiftrelwage lncpsaveshiftwage lncpslagrelshift lncpslagaveshift i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
					`educyear'  `raceyear' `stateyear' $racestatetrend 	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 	
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10				
	}

	esttab using "${tables}/tablea10.tex", replace /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat( mean10 N, labels( "Obs"  ) fmt(3 0 )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work" ) 
				
				
/***************************************************
	Table A11 - Migration
***************************************************/
		
	eststo clear
	
	foreach move in mvtot mv2 sty2  {
	foreach outcome in married nevmar div ed_lt_sp sngfern  movestate  {
		
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway"
		local controls yrsedfem yrsedmale sexratio 
			
			if "`outcome'" != "movestate" local regoutcome  `outcome'_`move'_10fem
			if "`outcome'" == "movestate" local regoutcome  `outcome'_10fem
			
			eststo `regoutcome': xi: reg `regoutcome' lncpsshiftrelwage lncpsaveshiftwage i.race_num i.educ_num i.year i.fipstate i.birthyr i.birthyr*i.year /// 
						 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
						`fe'  /// 		
						`controls' ///				
						[aweight=popfem], cluster(fipstate) 	
				local `outcome'`move' = _b[lncpsshiftrelwage]
				if "`move'" == "sty2" {
					local `outcome'pctstay =  (``outcome'sty2'/``outcome'mvtot')*100
					di "`outcome'pctstay'" 
					estadd scalar pctstay = ``outcome'pctstay'
					}		
	}
				if "`move'" == "mvtot" ///
				esttab *mvtot*fem movestate*fem using "${tables}/tablea11.tex" , replace /// 
				keep(lncps*rel* ) se se(3) b(3)  star (* .10 ** .05 *** .01)  nonotes noconstant noobs ///
				label	mtitle( "Married" "Nev. Marr."  "Divorced"  "Sp. More Ed"  "Fem. Earn" "Moved States") postfoot("") ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{A: Total }} \\ ")) 

				if "`move'" == "mv2" ///
				esttab *mv2*fem using  "${tables}/tablea11.tex" , append /// 
				keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonotes noconstant noobs ///
				label	nonum nomtitle prehead("") posthead("") postfoot("") ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{B: Moved States and...}} \\ ")) 

				if "`move'" == "sty2" ///
				esttab *sty2*fem using  "${tables}/tablea11.tex" , append /// 
				keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonotes noconstant noobs ///
				stat(pctstay , labels("Pct. Effect among Stayers") fmt(3 3 0 0 0 0 0))  ///
				label nonum	nomtitle prehead("") posthead("") ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{C: Did not Move and...}} \\ ")) 
				
	}
	

		
/**************************************************
	Table A12 - Effects by Male, Female Wage
***************************************************/
	
	eststo clear
	
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {
		
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 
						
		eststo: xi: reg `outcome' lncpsmaleshiftwage lncpsfemshiftwage i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
					`educyear'  `raceyear' `stateyear' $racestatetrend	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 			
			test lncpsmaleshiftwage = -1*lncpsfemshiftwage 
			estadd scalar test = r(p)
			estadd scalar fstat = r(F)
	
		}
		
	esttab using "${tables}/tablea12.tex", replace /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat(header test fstat, labels("Test Equal,Oppos:" "P-value" "F-statistic") fmt(0 3 3 )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work"  ) ///
		varlabels( lncpsmaleshiftwage "Effect of 10\% Increase in Male Wage" lncpsfemshiftwage "Effect of 10\% Increase in Female Wage")
			
			

/**************************************************
	Table A13 - Effects by Quartile of Male Growth
***************************************************/				
	
	eststo clear

	preserve
		
		gen panel_year = (year-1970)/10

		collapse (mean)  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem /// 
		(mean)  dlncpsshiftrelwage_maleq1 (mean) dlncpsshiftrelwage_maleq2 (mean) dlncpsshiftrelwage_maleq3 (mean) dlncpsshiftrelwage_maleq4 ///
		(mean) yrsedfem yrsedmale sexratio (rawsum) popfem [aweight=popfem] , by(educ_num race_num fipstate year panel_year)

		egen panelvar = group(educ_num race_num fipstate)
		xtset panelvar panel_year		
		
		
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {
		
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local dcontrols "D.yrsedfem D.yrsedmale  D.sexratio" 
							
		eststo: xi: reg D.`outcome' dlncpsshiftrelwage_maleq1 dlncpsshiftrelwage_maleq2 dlncpsshiftrelwage_maleq3 dlncpsshiftrelwage_maleq4 ///
					 i.educ_num*i.year i.race_num*i.year i.fipstate*i.year i.race_num*i.fipstate 	/// 		
					`dcontrols'  ///				
					[aweight=popfem], cluster(fipstate) 
		estadd ysumm
		summ `outcome' [aweight=popfem]
		estadd scalar mean10 = r(mean)*10

	}	

	esttab using "${tables}/tablea13.tex", replace /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat(mean10   N, labels("Mean Y" "Obs"  ) fmt(3 0  )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work" ) /// 
		varlabels( dlncpsshiftrelwage_maleq1 "10\% Increase in Rel. Wage x Q1 of D. Male Wage" dlncpsshiftrelwage_maleq2 "10\% Increase in Rel. Wage x Q2 of D. Male Wage" /// 
		dlncpsshiftrelwage_maleq3 "10\% Increase in Rel. Wage x Q3 of D. Male Wage" dlncpsshiftrelwage_maleq4 "10\% Increase in Rel. Wage x Q4 of D. Male Wage")
	restore


/***************************************************
	Table A14 - Effect of Relative Wage on PrWomanEarnsMore
*****************************************************/
	
	eststo clear

	
	preserve	
		egen uniquegroup = group(educ race fipstate)
		
		collapse fearnsmore lncpsshiftrelwage lncpsaveshiftwage lncpsmaleshiftwage lncpsfemshiftwage yrsedfem yrsedmale sexratio (sum) popfem, by(uniquegroup educ_num race_num fipstate year) 
		
		** divide prwomanearns more by 10 so coefficients are interpreted as effect of 10% increase in relative wage/female wage/male wage
		replace fearnsmore = fearnsmore/10
		
		** multiply back by 10 to use for means in table
		gen fearns10 = fearnsmore*10 
			
		eststo: xi: reg  fearnsmore lncpsshiftrelwage lncpsaveshiftwage i.uniquegroup /// 
		 i.educ_num*i.year  i.race_num*i.year i.fipstate*i.year yrsedfem yrsedmale sexratio [aweight=popfem], cluster(fipstate)
		sum fearns10 [weight=popfem]
		estadd scalar mean = r(mean)

		eststo: xi: reg  fearnsmore lncpsmaleshiftwage lncpsfemshiftwage i.uniquegroup /// 
		 i.educ_num*i.year  i.race_num*i.year i.fipstate*i.year yrsedfem yrsedmale sexratio [aweight=popfem], cluster(fipstate)
		sum fearns10 [weight=popfem]
		estadd scalar mean = r(mean)
		
		esttab  using "${tables}/tablea14.tex", replace /// 
		keep(*lncps* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) nonum nonotes noconstant ///
		stat(N mean,	labels("Obs" "Mean Y") fmt(0 3)) ///
		label nomtitle  /// 
		mgroups("PrWomanEarnsMore", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" lncpsmaleshiftwage "Effect of 10\% Increase in Male Wage" lncpsfemshiftwage "Effect of 10\% Increase in Female Wage")

		
	 restore

	 
/***************************************************
	Table A15 - Effects Controlling for PrWomanEarnsMore
*****************************************************/
	
	eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {
		
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale  sexratio 
		
		eststo:  xi: reg `outcome' lncpsshiftrelwage lncpsaveshiftwage fearnsmore i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
					 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 		
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10	
	}

	esttab using "${tables}/tablea15.tex", replace /// 
		keep(*lncps*rel* fearnsmore ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat( mean10 N, labels("Mean" "Obs"  ) fmt(3 0 )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work" ) /// 
		varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" fearnsmore "Effect of 10 p.p. Increase in PrWomanEarnsMore")
	

	
/***************************************************************************
	Table A16 - Insensitivity to Add'l Controls for Alternative Mechanisms
*****************************************************************************/


eststo clear
	
** Save first stage results
	
	preserve 
	use firststage.dta
	
	tab educ, g(e)
		local maxed =r(r)
	tab race, g(r)
		local maxrace =r(r)
	tab fipstate, g(s)
		local maxstate= r(r)

	global threeway ""

	forvalues e = 1/`maxed' {
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global threeway $threeway e`e's`s'r`r'
		
	}
	}
	}

		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway"
			
		gen lncpsrelwage_10 = lncpsrelwage/10

		eststo first_popincar: xi: reg lncpsrelwage_10 lncpsshiftrelwage i.race_num i.educ_num i.year i.fipstate /// 
						`educyear'  `raceyear' `stateyear' 	/// 
						`fe'    /// 		
						yrsedfem yrsedmale sexratio lnpopfem lnpopmale incarc* ///				
						[aweight=cps_pop], cluster(fipstate) 	
	

		eststo first_popincarmanuf: xi: reg lncpsrelwage_10 lncpsshiftrelwage i.race_num i.educ_num i.year i.fipstate /// 
						`educyear'  `raceyear' `stateyear' 	/// 
						`fe'  /// 		
						 yrsedfem yrsedmale sexratio i.year*manufshare_1970 lnpopfem lnpopmale incarc* ///				
						[aweight=cps_pop], cluster(fipstate) 

			
	restore
	
	tab educ
		local maxed =r(r)
	tab race
		local maxrace =r(r)
	tab fipstate
		local maxstate= r(r)

	global threeway ""

	forvalues e = 1/`maxed' {
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global threeway $threeway e`e's`s'r`r'
		
	}
	}
	}	
	
	
	global racestatetrend ""
	
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global racestatetrend $racestatetrend s`s'r`r'year
		
	}
	}
		
						
	foreach outcome in share_married_10fem share_nevmar_10fem cohab_offic_10fem share_div_10fem  ed_lt_sp_10fem  sngfern_10fem  { 
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 	
		local controls yrsedfem yrsedmale sexratio 
	
		preserve 
	
			*Now control for population and incarc
			eststo popincar`outcome': xi: reg `outcome' ///
					lncpsshiftrelwage lncpsaveshiftwage lnpopfem lnpopmale incarcfem incarcmale ///
					 i.race_num i.educ_num i.year i.fipstate i.birthyr i.birthyr*i.year /// 
						`educyear'  `raceyear' `stateyear' $racestatetr	/// 
						`fe'  /// 		
						`controls' ///				
						[aweight=popfem], cluster(fipstate) 	


		*Now control for male variance
			eststo malevar`outcome': xi: reg `outcome' lncpsshiftrelwage lncpsaveshiftwage p5010diff_malelnwage p9010diff_malelnwage p9050diff_malelnwage i.race_num i.educ_num i.year i.fipstate i.birthyr i.birthyr*i.year /// 
						 lnpopfem lnpopmale incarcfem incarcmale /// 
						 `educyear'  `raceyear' `stateyear' $racestatetr	/// 
						`fe'  /// 		
						`controls' ///				
						[aweight=popfem], cluster(fipstate) 	
		
			*Now control for share of manufacturing in 1970
			eststo manuf`outcome': xi: reg `outcome' ///
					lncpsshiftrelwage lncpsaveshiftwage p5010diff_malelnwage p9010diff_malelnwage p9050diff_malelnwage ///
					lnpopfem lnpopmale incarcfem incarcmale ///
					i.year*manufshare_1970 ///
					i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
						`educyear'  `raceyear' `stateyear' $racestatetrend	/// 
						`fe'  /// 		
						`controls'  ///				
						[aweight=popfem], cluster(fipstate) 	

			
		restore
		
		}
				esttab popincar*married* popincar*nevmar* popincar*div* popincar*coh* popincar*ed_lt*  popincar*sng*  first_popincar using ///
				"${tables}/tablea16.tex", replace /// 
				keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonum nonotes noconstant noobs ///
				label	mtitle( "Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner" "ln Rel. Wage")	 ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{A: + ln(Pop.), Share Incarc.}} \\ "))	postfoot("")

				esttab malevar*married* malevar*nevmar* malevar*div* malevar*coh*  malevar*ed_lt* malevar*sng*  first_popincar  using ///
				"${tables}/tablea16.tex" , append /// 
				keep(lncps*rel* ) se se(3) b(3)  star (* .10 ** .05 *** .01)  nonum nonotes noconstant noobs label	  ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{B: + Male Wage Variance}} \\ ")) nomtitle prehead("") posthead("") postfoot("")	
	
				esttab manuf*married* manuf*nevmar* manuf*div* manuf*coh*  manuf*ed_lt*    manuf*sng*  first_popincarmanuf using ///
				"${tables}/tablea16.tex", append /// 
				keep(lncps*rel* ) se  se(3) b(3)  star (* .10 ** .05 *** .01)  nonum nonotes noconstant noobs ///
				stat(N , labels( "Obs" ) fmt(  0))  label	nomtitle	 ///
				varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage" , blist(lncpsshiftrelwage "\midrule \it{\underline{C: + 1970 Manuf.*Yr. FE}} \\ "))	prehead("") posthead("")
				
				
	

/***************************************************************************
	Table A21 - Effects removing dynamic updating
*****************************************************************************/

eststo clear
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem  {

		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 			
		local controls yrsedfem yrsedmale  sexratio 

		eststo: xi: reg `outcome' lncpsshiftrelwage_noupdate lncpsaveshiftwage_noupdate i.race_num i.educ_num i.year i.fipstate  i.birthyr i.birthyr*i.year /// 
				 `educyear'  `raceyear' `stateyear' $racestatetrend	/// 
				`fe'  /// 		
				`controls' ///				
				[aweight=popfem], cluster(fipstate) 	
			estadd local Ave_wage = "Yes"				
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10
					
	}

		esttab using "${tables}/tablea21.tex", replace /// 
				keep(*lncps*rel*  ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
				stat(mean10 N Ave_wage, /// 
				labels("Mean Y"  "Obs"  "Average Wage") /// 
				fmt(3 0 0 )) varlabels(lncpsshiftrelwage "Effect of 10\% Increase in Rel. Wage") ///
				label mtitle( "Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work") 
							
				

/***************************************************************************
	Table A23 - Heterogeneity by Attainment of College
*****************************************************************************/

	eststo clear
	
	use $data/tablea22_23.dta, replace // data with shift share created with college/non-college split
	
	** Prep data
	
	tab educ
		local maxed =r(r)
	tab race
		local maxrace =r(r)
	tab fipstate
		local maxstate= r(r)
	
	global threeway ""

	forvalues e = 1/`maxed' {
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global threeway $threeway e`e's`s'r`r'
		
	}
	}
	}

	global racestatetrend ""
	
	forvalues s = 1/`maxstate' {
	forvalues r = 1/`maxrace' {
			
		global racestatetrend $racestatetrend s`s'r`r'year
		
	}
	}	
	
	foreach outcome in  share_married_10fem share_nevmar_10fem share_div_10fem ed_lt_sp_10fem cohab_offic_10fem sngfern_10fem ave_wkhrs_10fem	{	
	
		local educyear = "i.educ_num*i.year" 
		local raceyear = "i.race_num*i.year"
		local stateyear = "i.fipstate*i.year" 
		local fe = "$threeway" 			
		local controls yrsedfem yrsedmale  sexratio 

		eststo : xi: reg `outcome' lncpsshiftrelwage_hied lncpsshiftrelwage_loed   /// 
					lncpsaveshiftwage_hied lncpsaveshiftwage_loed  ///
					i.race_num i.educ_num i.year i.fipstate i.birthyr i.birthyr*i.year /// 
					 `educyear'  `raceyear' `stateyear' $racestatetrend  	/// 
					`fe'  /// 		
					`controls' ///				
					[aweight=popfem], cluster(fipstate) 				
			summ `outcome' [aweight=popfem]
			estadd scalar mean10 = r(mean)*10

					
	}	
	

	esttab using "${tables}/tablea23.tex", replace /// 
		keep(*lncps*rel* ) se r2 se(3) b(3)  star (* .10 ** .05 *** .01) numbers nonotes noconstant ///
		stat( mean10 N,  labels("Obs"  ) fmt(3 0 )) ///
		label mtitle("Marr." "Nev. Marr." "Divorced" "Cohab" "Sp. More Ed." "Fem. Earner"  "Hrs. Work" ) 
		

	
/**********************************************
	TABLE A24 - NSFH Descriptive Analysis
************************************************/

use $data/tablea24.dta, clear

foreach resp in  wife husb{
foreach outcome in vhappymar_`resp'  martroub_`resp' phys_ly_`resp' {

	eststo `outcome': xi: reg `outcome'  lnrelinc lntotalinc ///
					zeroinc_wife zeroinc_husb ///
					age_wife age_husb age_wife_sq age_husb_sq ///
					i.region /// 
					i.black_husb i.white_husb i.hisp_husb i.other_husb ///
					i.black_wife i.white_wife i.hisp_wife i.other_wife ///
					i.lths_wife i.lths_husb i.scol_wife i.scol_husb ///
					yrsed_wife yrsed_husb ///					
					[aweight=spwt] if age_wife>=22 & age_wife<=44 &  income_wife < income_husb, vce(robust)
	estadd ysumm
						
}

	if "`resp'" == "wife" ///
	esttab  vhappymar_`resp' martroub_`resp'   phys_ly_`resp' ///
		using "$tables/tablea24.tex", replace keep(lnrelinc) label nonotes noconstant nonumbers nodepvar stat(ymean N, labels("Mean Y" "Obs") ///
		fmt(3 0))  se(3) b(3)  star (* .10 ** .05 *** .01)  ///
		 mtitle("V. Happy" "Marr. Trouble" "Physical Last Year") postfoot("") ///
		 varlabels( , blist(lnrelinc "\midrule \it{\underline{A: Wife's Response}} \\ "))

	if "`resp'" == "husb" ///
	esttab  vhappymar_`resp' martroub_`resp' phys_ly_`resp' ///
		using "$tables/tablea24.tex", append keep(lnrelinc) label nonotes noconstant nonumbers nodepvar stat(ymean N, labels( "Mean Y" "Obs") ///
		fmt(3 0))  se(3) b(3)  star (* .10 ** .05 *** .01)  ///
		 nomtitle prehead("") posthead("") ///
		 varlabels( , blist(lnrelinc "\midrule \it{\underline{B: Husband's Response}} \\ "))
}

*/
	
	log close


			